<?php
// +-------------------------------------------------------------------------------
// | DingZone [ A Rapid Development Framework For Dingtalk ]
// +-------------------------------------------------------------------------------
// | 钉钉机器人文本消息 v1.0
// |
// | Copyright (c) 2014-2018 http://www.heimalanshi.com All rights reserved.
// | Author : Jie
// | Date : 2018-08-09
// +-------------------------------------------------------------------------------

namespace ding\msg\robot;

/**
 * 给机器人发送的文本消息
 *
 * @package ding\msg\robot
 */
class TextRobotMsg extends RobotMsg {
    protected $content;
    protected $atMobiles;
    protected $isAtAll;

    /**
     * 文本消息构造函数
     *
     * @param $content
     * @param array $atMobiles
     * @param bool $isAtAll
     */
    public function __construct($content, $atMobiles = [], $isAtAll = false) {
        parent::__construct("text");
        $this->content = $content;
        $this->atMobiles = $atMobiles;
        $this->isAtAll = $isAtAll;
    }

    /**
     * 转换为可发送的消息
     * {
     *        "msgtype": "text",
     *        "text": {
     *            "content": "我就是我, @156xxxx8827 是不一样的烟火"
     *        },
     *        "at": {
     *            "atMobiles": [
     *                "156xxxx8827",
     *                "189xxxx8325"
     *            ],
     *            "isAtAll": false
     *        }
     * }
     * @return array
     */
    public function toMsg() {
        return [
            'msgtype' => $this->msgtype,
            'text' => [
                'content' => $this->content
            ],
            'at' => [
                'atMobiles' => $this->atMobiles,
                'isAtAll' => $this->isAtAll
            ]
        ];
    }

}